package com.xiang.reggie.common;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.slf4j.impl.StaticMDCBinder;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;


/**
 * 结果
 * 通用返回结果，服务端响应的数据
 *
 * @author Lightswitch
 * @date 2022/12/14
 */
@Data
@ApiModel("统一封装结果对象")
public class Result<T> implements Serializable {

    @ApiModelProperty("自定义的响应状态码")
    private Integer code;   //编码 ： 1 成功 0 失败
    @ApiModelProperty("错误消息")
    private String msg;     //错误消息
    @ApiModelProperty("数据")
    private T data;         //数据
    @ApiModelProperty("动态数据")
    private Map map = new HashMap();    //动态数据

    public static <T> Result<T> success(T object) {
        Result<T> result = new Result<T>();
        result.data = object;
        result.code = 1;
        return result;
    }

    public static <T> Result<T> error(String msg) {
        Result result = new Result();
        result.msg = msg;
        result.code = 0;
        return result;
    }

    public Result<T> add(String key, Object value) {
        this.map.put(key, value);
        return this;
    }


}
